package model;

import entities.Department;
import java.io.Serializable;
import java.util.ArrayList;
import javax.swing.AbstractListModel;
import javax.swing.MutableComboBoxModel;

public class ViewDepartmentComboBoxModel extends AbstractListModel implements MutableComboBoxModel, Serializable {

    private ArrayList<Department> list;
    private Department selectedItem;

    public ViewDepartmentComboBoxModel() {
        list = new ArrayList<Department>();
    }
    
    public ViewDepartmentComboBoxModel(ArrayList<Department> list) {
        this.list = list;
    }

    @Override
    public int getSize() {
        return list.size();
    }

    @Override
    public Object getElementAt(int index) {
        return list.get(index);
    }

    @Override
    public void addElement(Object item) {
        list.add((Department) item);
    }

    public void addElementAt(int index, Department dep) {
        list.add(index, dep);
    }

    @Override
    public void removeElement(Object obj) {
        list.remove(obj);
    }

    @Override
    public void insertElementAt(Object item, int index) {
        list.add(index, (Department) item);
    }

    @Override
    public void removeElementAt(int index) {
        list.remove(index);
    }

    @Override
    public void setSelectedItem(Object anItem) {
        selectedItem = (Department) anItem;
    }

    @Override
    public Object getSelectedItem() {
        return selectedItem;
    }

    public boolean addAll(ArrayList<Department> list) {
        return this.list.addAll(list);
    }
    
    public void setViewEmployee() {
        for(Department dep : list) {
            if(dep.getDepartmentID() == 1)
                list.remove(dep);
            break;
        }
    }
}
